/**
  ******************************************************************************
  * @file    Project/Application/Main/BOOT.c 
  * @author  Feirui_Joe
  * @version V0.1
  * @date    07/26/2010
  * @brief   program boot up fine
  ******************************************************************************
  * @copy
  *
  * <h2><center>&copy; COPYRIGHT 2010 Feirui</center></h2>
  */ 


/**
  * @brief  INCLUDE FILES.
  */
#ifndef	APP_GLOBALS_BOOT
#define	APP_GLOBALS_BOOT
#include <includes.h>


/*$PAGE*//**
  * @brief functions definition
  */
static  void  SysClearAllRAM       (void);
static  void  CM3Periph_DeInit     (void);
static  void  SystemInitLoading    (void);


/*$PAGE*//**
  * @brief  This is the standard entry point for C code.
  * @param  none.
  * @return None
  */
 

int  main (void)
{
#ifdef EnableCheckOS_errOpt
    uint8_t  os_err;
#endif
    
    
    /***************************Check Reboot Solution***********/
    
    
    
    /***************************System Start********************/
    __disable_irq();                                              /* Disable all interrupts  			      */
    SysClearAllRAM();                                             /* Clear All RAM        			        */
    SystemInitLoading();
    
    /***************************UCOS-II*************************/
    OSInit();                                                   /* Initialize "uC/OS-II".     */

#ifdef EnableCheckOS_errOpt    
    os_err = 
#endif
    OSTaskCreateExt         ((void (*)(void *)) App_Task_START,
                             (void          * ) 0,
                             (OS_STK        * )&App_TaskStk_START   [APP_TASK_STK_SIZE_START - 1],
                             (INT8U           ) APP_TASK_PRIO_START,
                             (INT16U          ) APP_TASK_PRIO_START,
                             (OS_STK        * )&App_TaskStk_START   [0],
                             (INT32U          ) APP_TASK_STK_SIZE_START,
                             (void          * ) 0,
                             (INT16U          )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));
    
#if (OS_TASK_NAME_EN > 0u)
    OSTaskNameSet(APP_TASK_PRIO_START, (uint8_t *)APP_TASK_NAME_START, &os_err);
#endif
    
    OSStart();                                                  /* Start multitasking in UCOS-II*/
    
    return (0);
}


/*$PAGE*//**
  * @brief  Initial CM3,Periph and CMSIS
  * @param  none
  * @return none.
  * @Note   none.
  */
static  void  SystemInitLoading     (void)
{
  CM3Periph_DeInit();											                      /* Make CM3 & Periph to default value */
	SystemInit();												                          /* CMSIS System Initial 			        */	
}


/**
  * @brief  Clear All RAM
  * @param  none
  * @return none.
  * @Note   none.
  */
static  void  SysClearAllRAM     (void)
{
	uint8_t * RAMpoint=(uint8_t *)(SysRAMClear_StartAdr);
	uint16_t  i;
	
	for(i=0;i<(SysRAMClear_EndAdr-SysRAMClear_StartAdr);i++)
	  * (RAMpoint++)=0;
}



/**
  * @brief  Make CM3 & Periph to default value
  * @param  none
  * @return none.
  * @Note   none.
  */
static  void  CM3Periph_DeInit     (void)
{
#ifdef __STM32F10x_RCC_H
//  RCC_DeInit();											 /* make default value for RCC    */
#endif
    
#ifdef __STM32F10x_WWDG_H
    WWDG_DeInit();										 /* make default value for WWDG   */
#endif
    
#ifdef __STM32F10x_BKP_H
//	BKP_DeInit();											 /* make default value for BKP    */
#endif
    
#ifdef __STM32F10x_PWR_H
//  PWR_DeInit();											 /* make default value for PWR    */
#endif
    
#ifdef __STM32F10x_CEC_H
    CEC_DeInit();											 /* make default value for CEC   */
#endif
    
#ifdef __STM32F10x_EXTI_H
    EXTI_DeInit();										 /* make default value for EXTI   */
#endif
    
#ifdef __STM32F10x_GPIO_H
    GPIO_DeInit(GPIOA);								 /* make default value for GPIOA  */
    GPIO_DeInit(GPIOB);								 /* make default value for GPIOB  */
    GPIO_DeInit(GPIOC);								 /* make default value for GPIOC  */
    GPIO_DeInit(GPIOD);								 /* make default value for GPIOD  */
    GPIO_DeInit(GPIOE);								 /* make default value for GPIOE  */
/*  GPIO_DeInit(GPIOF);		*/					 /* make default value for GPIOF  */
/*  GPIO_DeInit(GPIOG);		*/ 			  	 /* make default value for GPIOG  */
    GPIO_AFIODeInit();								 /* make default value for AFIO   */
#endif
    
#ifdef __STM32F10x_TIM_H
    TIM_DeInit(TIM1);									 /* make default value for TM1    */
    TIM_DeInit(TIM2);									 /* make default value for TM2    */
    TIM_DeInit(TIM3);									 /* make default value for TM3    */
    TIM_DeInit(TIM4);									 /* make default value for TM4    */
    TIM_DeInit(TIM5);		  					 /* make default value for TM5    */
/*  TIM_DeInit(TIM6);		*/  					 /* make default value for TM6    */
/*  TIM_DeInit(TIM7);		*/  					 /* make default value for TM7    */
    TIM_DeInit(TIM8);		  					 /* make default value for TM8    */
/*  TIM_DeInit(TIM9);		*/  					 /* make default value for TM9    */
/*  TIM_DeInit(TIM10);	*/  					 /* make default value for TM10   */
/*  TIM_DeInit(TIM11);	*/  					 /* make default value for TM11   */
/*  TIM_DeInit(TIM12);	*/  					 /* make default value for TM12   */
/*  TIM_DeInit(TIM13);	*/  					 /* make default value for TM13   */
/*  TIM_DeInit(TIM14);	*/  					 /* make default value for TM14   */
/*  TIM_DeInit(TIM15);	*/  					 /* make default value for TM15   */
/*  TIM_DeInit(TIM16);	*/  					 /* make default value for TM16   */
/*  TIM_DeInit(TIM17);	*/  					 /* make default value for TM17   */
#endif
    
#ifdef __STM32F10x_DMA_H
	  DMA_DeInit(DMA1_Channel1);					 /* make default value for DMA1.1 */
	  DMA_DeInit(DMA1_Channel2);					 /* make default value for DMA1.2 */
	  DMA_DeInit(DMA1_Channel3);					 /* make default value for DMA1.3 */
	  DMA_DeInit(DMA1_Channel4);					 /* make default value for DMA1.4 */
	  DMA_DeInit(DMA1_Channel5);					 /* make default value for DMA1.5 */
	  DMA_DeInit(DMA1_Channel6);					 /* make default value for DMA1.6 */
	  DMA_DeInit(DMA1_Channel7);					 /* make default value for DMA1.7 */
/*	DMA_DeInit(DMA2_Channel1);	*/				/* make default value for DMA2.1 */
/*	DMA_DeInit(DMA2_Channel2);	*/				/* make default value for DMA2.2 */	
/*	DMA_DeInit(DMA2_Channel3);	*/				/* make default value for DMA2.3 */	
/*	DMA_DeInit(DMA2_Channel4);	*/				/* make default value for DMA2.4 */
/*	DMA_DeInit(DMA2_Channel5);	*/				/* make default value for DMA2.5 */
#endif
    
#ifdef __STM32F10x_ADC_H
	  ADC_DeInit(ADC1);										 /* make default value for ADC1   */
	  ADC_DeInit(ADC2);										 /* make default value for ADC2   */
	  ADC_DeInit(ADC3);										 /* make default value for ADC3   */
#endif
    
#ifdef __STM32F10x_DAC_H
    DAC_DeInit();										   /* make default value for DAC   */
#endif
    
#ifdef __STM32F10x_I2C_H
    I2C_DeInit(I2C1);									 /* make default value for I2C1   */
    I2C_DeInit(I2C2);									 /* make default value for I2C2   */
#endif
    
#ifdef __STM32F10x_SPI_H
    SPI_I2S_DeInit(SPI1);							 /* make default value for SPI1   */
    SPI_I2S_DeInit(SPI2);							 /* make default value for SPI2   */
    SPI_I2S_DeInit(SPI3);							 /* make default value for SPI3   */
#endif
    
#ifdef __STM32F10x_SDIO_H
    SDIO_DeInit();										 /* make default value for SDIO  */
#endif
    
#ifdef __STM32F10x_FSMC_H
    FSMC_NORSRAMDeInit(FSMC_Bank1_NORSRAM1);			/* make default value for NOR1  */
    FSMC_NORSRAMDeInit(FSMC_Bank1_NORSRAM2);			/* make default value for NOR2  */
    FSMC_NORSRAMDeInit(FSMC_Bank1_NORSRAM3);			/* make default value for NOR3  */
    FSMC_NORSRAMDeInit(FSMC_Bank1_NORSRAM4);			/* make default value for NOR4  */
    FSMC_NANDDeInit(FSMC_Bank2_NAND);							/* make default value for NAN2  */
    FSMC_NANDDeInit(FSMC_Bank3_NAND);							/* make default value for NAN3  */
    FSMC_PCCARDDeInit();										      /* make default value for PCC  */
#endif
    
#ifdef __STM32F10x_USART_H
    USART_DeInit(USART1);										      /* make default value for USART1 */
    USART_DeInit(USART2);										      /* make default value for USART2 */
    USART_DeInit(USART3);										      /* make default value for USART3 */
    USART_DeInit(UART4);										      /* make default value for UART4  */
    USART_DeInit(UART5);										      /* make default value for UART5  */
#endif
    
#ifdef __STM32F10x_CAN_H	
	  CAN_DeInit(CAN1);											          /* make default value for CAN1   */
	  CAN_DeInit(CAN2);											          /* make default value for CAN2   */
#endif
    
#ifdef __MISC_H
    NVIC_DeInit();												        /* make default value for NVIC */
    NVIC_SCBDeInit();											        /* make default value for SCB  */
    
    /* Set the Vector Table base address at 0x0800x000 */
    NVIC_SetVectorTable(NVIC_VectTab_FLASH,ApplicationAdrOffset);
    NVIC_PriorityGroupConfig(NVIC_PriorityGroupx);
#endif
}


/*$PAGE*/#endif	/* APP_GLOBALS_BOOT */